package cn.gdut.chengcai.admin.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.gdut.chengcai.base.ConstantUtil;
import cn.gdut.chengcai.base.JsonUtil;
import cn.gdut.chengcai.base.MessageUtil;
import cn.gdut.chengcai.base.ResponseData;
import cn.gdut.chengcai.param.BaseSearchParam;

@Controller
public class Admin_MainController {

	/**
	 * 重置页码操作
	 */
	@RequestMapping(value = "/admin/resetPageAction", method = RequestMethod.POST)
	@ResponseBody
	public ResponseData<Object> resetPageAction(@RequestBody String jsonString, HttpSession session, ModelMap map) {
		ResponseData<Object> result = new ResponseData<>();
		result.setIsSuccess(false);

		BaseSearchParam param = (BaseSearchParam) JsonUtil.fromJson(jsonString, BaseSearchParam.class);

		try {
			if (null != param.getPageNo()) {
				session.setAttribute(ConstantUtil.STR_PAGE_NO, param.getPageNo());
			} else {
				session.setAttribute(ConstantUtil.STR_PAGE_NO, "1");
			}
			result.setIsSuccess(true);
		} catch (Exception e) {
			result.setMessage(MessageUtil.SYSTEM_ERROR);
		}
		return result;
	}

}